clear
set more off


********************************************************************************
*                      FERTILITY  : MAIN ESTIMATES                             *
********************************************************************************


***   1.   NATIVE HUSBAND - FOREIGN WIFE   ***

use "$data\MSN_final_dataset.dta" , clear

* keep marriages from 1998
destring ym, replace
keep if ym>=1998
gen year=ym
drop HOM 
gen HOM = hbc==wbc
lab var HOM "Homogamous"
gen HET = HOM!=1
lab var HET "Heterogamous"
gen HET_IT =  (hbc==0 & wbc>0) | ( hbc>0 & wbc==0) 
lab var HET_IT "Heterogamous-Italian"
gen HETW = HET==1 & wbc!=0
gen HETH = HET==1 & hbc!=0

*  Marriages with NATIVE HUSBAND 
keep if hbc==0

* Treatment
gen nat= wbc
merge m:1 nat using "$data\CodiciStatiEsteri.dta" , keepusing(EUII)
tab _merge
drop _merge
replace EUII=4 if nat==224 
replace EUII=4 if nat==258  
replace EUII=4 if nat==259  
replace EUII=4 if nat==260  
replace EUII=4 if nat==261  
replace EUII=6 if nat==317  
recode EUII (.=0)
lab define eui3 0 "Italian" 1 "EU15"  2 "EU2004" 3 "EU2007" 4 "EU_Other" 5 "Africa" 6 "Asia" 7 "America_South" 8 "OECD" 
label values EUII eui3
tab EUII, gen(euii)
rename euii1 Italian
rename euii2 eu15
rename euii3 eu2004
rename euii4 eu2007
rename euii5 euother
rename euii6 africa
rename euii7 asia
rename euii8 americas
rename euii9 oecd
codebook EUII
drop if EUII==.

* Time 
tab year
tab year, gen(t)
rename t1 t1998
rename t2 t1999
rename t3 t2000
rename t4 t2001
rename t5 t2002
rename t6 t2003
rename t7 t2004
rename t8 t2005
rename t9 t2006
rename t10 t2007
rename t11 t2008
rename t12 t2009
rename t13 t2010
rename t14 t2011
rename t15 t2012
gen post2003= year>=2003
gen post2004= year>=2004
gen post2005= year>=2005
gen post2006= year>=2006
gen post2007= year>=2007

* Interaction
gen eu2004post2003= eu2004*post2003
gen eu2004post2004= eu2004*post2004
gen eu2004post2006= eu2004*post2006
gen eu2004post2007= eu2004*post2007
gen eu2007post2003= eu2007*post2003
gen eu2007post2004= eu2007*post2004
gen eu2007post2006= eu2007*post2006
gen eu2007post2007= eu2007*post2007

egen newEU=rmax(eu2004 eu2007)
egen newEUxPostEU=rmax(eu2004post2004 eu2007post2007)
forval i=1/159 {
gen wbcyear`i' = dwbc`i'*year
}
tab provres, gen(dprov)
forval i=1/`r(r)' {
gen provtrend`i' = dprov`i'*year
}


* Fertility outcome

gen withchild3y = ((mdate+36)>=c1date)

********************************************************************************
* Table 7: Columns 1-4
* Probability of having a child before and after the EU enlargements, DID estimates

areg withchild3y newEUxPostEU i.year i.provres if year<=2011, absorb(wbc)  vce(cluster provres)
outreg2 using "$output\fertility_newEU.xls" , keep(newEUxPostEU) replace 
areg withchild3y newEUxPostEU i.year provtrend1-provtrend99 wbcyear1-wbcyear159 if year<=2011, absorb(wbprov) vce(cluster provres)
outreg2 using "$output\fertility_newEU.xls" , keep(newEUxPostEU) append 

gen dropsample = (eu2004==1&(year>2000|year<2003)) | (eu2007==1&(year>2004|year<2006))
areg withchild3y newEUxPostEU i.year i.provres if dropsample!=1, absorb(wbc)  vce(cluster provres)
outreg2 using "$output\fertility_newEU.xls" , keep(newEUxPostEU) replace 
areg withchild3y newEUxPostEU i.year provtrend1-provtrend99 wbcyear1-wbcyear159 if dropsample!=1, absorb(wbprov) vce(cluster provres)
outreg2 using "$output\fertility_newEU.xls" , keep(newEUxPostEU) append 






***   2.   NATIVE WIFE - FOREIGN HUSBAND    ***

use "$data\MSN_final_dataset.dta" , clear

* keep marriages from 1998
destring ym, replace
keep if ym>=1998
gen year=ym
cap drop HOM 
gen HOM = hbc==wbc
lab var HOM "Homogamous"
gen HET = HOM!=1
lab var HET "Heterogamous"
gen HET_IT =  (hbc==0 & wbc>0) | ( hbc>0 & wbc==0) 
lab var HET_IT "Heterogamous-Italian"
gen HETW = HET==1 & wbc!=0
gen HETH = HET==1 & hbc!=0

* Keep NATIVE WIFE 
keep if wbc==0

* Treatment
gen nat= hbc
merge m:1 nat using "$data\CodiciStatiEsteri.dta" , keepusing(EUII)
tab _merge
drop _merge
replace EUII=4 if nat==224 
replace EUII=4 if nat==258  
replace EUII=4 if nat==259  
replace EUII=4 if nat==260  
replace EUII=4 if nat==261  
replace EUII=6 if nat==317  
recode EUII (.=0)
lab define eui3 0 "Italian" 1 "EU15"  2 "EU2004" 3 "EU2007" 4 "EU_Other" 5 "Africa" 6 "Asia" 7 "America_South" 8 "OECD" 
label values EUII eui3
tab EUII, gen(euii)
rename euii1 Italian
rename euii2 eu15
rename euii3 eu2004
rename euii4 eu2007
rename euii5 euother
rename euii6 africa
rename euii7 asia
rename euii8 americas
rename euii9 oecd
codebook EUII
drop if EUII==.

* Time 
tab year
tab year, gen(t)
rename t1 t1998
rename t2 t1999
rename t3 t2000
rename t4 t2001
rename t5 t2002
rename t6 t2003
rename t7 t2004
rename t8 t2005
rename t9 t2006
rename t10 t2007
rename t11 t2008
rename t12 t2009
rename t13 t2010
rename t14 t2011
rename t15 t2012
gen post2003= year>=2003
gen post2004= year>=2004
gen post2005= year>=2005
gen post2006= year>=2006
gen post2007= year>=2007

* Interaction
gen eu2004post2003= eu2004*post2003
gen eu2004post2004= eu2004*post2004
gen eu2004post2006= eu2004*post2006
gen eu2004post2007= eu2004*post2007
gen eu2007post2003= eu2007*post2003
gen eu2007post2004= eu2007*post2004
gen eu2007post2006= eu2007*post2006
gen eu2007post2007= eu2007*post2007

egen newEU=rmax(eu2004 eu2007)
egen newEUxPostEU=rmax(eu2004post2004 eu2007post2007)
forval i=1/153 {
gen hbcyear`i' = dhbc`i'*year
}
tab provres, gen(dprov)
forval i=1/`r(r)' {
gen provtrend`i' = dprov`i'*year
}

* Fertility outcome

gen withchild3y = ((mdate+36)>=c1date)

********************************************************************************
* Table 7: Columns 5-8
* Probability of having a child before and after the EU enlargements, DID estimates

areg withchild3y newEUxPostEU i.year i.provres if year<=2011, absorb(hbc)  vce(cluster provres)
outreg2 using "$output\fertility_newEU.xls" , keep(newEUxPostEU) append 
areg withchild3y newEUxPostEU i.year provtrend1-provtrend99 hbcyear1-hbcyear153 if year<=2011, absorb(hbprov) vce(cluster provres)
outreg2 using "$output\fertility_newEU.xls" , keep(newEUxPostEU) append 

gen dropsample = (eu2004==1&(year>2000|year<2003)) | (eu2007==1&(year>2004|year<2006))
areg withchild3y newEUxPostEU i.year i.provres if dropsample!=1, absorb(hbc)  vce(cluster provres)
outreg2 using "$output\fertility_newEU.xls" , keep(newEUxPostEU) replace 
areg withchild3y newEUxPostEU i.year provtrend1-provtrend99 hbcyear1-hbcyear153 if dropsample!=1, absorb(hbprov) vce(cluster provres)
outreg2 using "$output\fertility_newEU.xls" , keep(newEUxPostEU) append 


